package com.yeyks.controller.finance;

import com.yeyks.account.dal.domain.AccountInfo;
import com.yeyks.annotation.NeedToken;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.base.PageResult;
import com.yeyks.common.em.accountinfo.AccountInfoTypeEnum;
import com.yeyks.common.exception.ServiceException;
import com.yeyks.common.param.WithdrawalOrderParam;
import com.yeyks.common.param.finance.FinanceWithdrawalParam;
import com.yeyks.common.result.withdrawalorder.HotelWithdrawalOrderResult;
import com.yeyks.commonReference.service.hotel.HotelWithdrawalOrderService;
import com.yeyks.hotel.dal.domain.HotelWithdrawalOrder;
import com.yeyks.web.AccountUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 财务vip酒店财务模块接口
 *
 * @author shuai
 * @date 2019-07-09
 */
@Slf4j
@Api(tags = "财务vip酒店财务模块接口")
@RestController
@RequestMapping("/vip/hotel/finance")
public class FinanceVipHotelController {

    @Autowired
    private HotelWithdrawalOrderService hotelWithdrawalOrderService;

    @NeedToken
    @ApiOperation(value = "申请提现", notes = "成功返回true,失败抛出错误信息")
    @PostMapping("/withdrawal")
    public AjaxResponseBody<Boolean> withdrawal(@Validated FinanceWithdrawalParam financeWithdrawalParam) {
        AccountInfo loginUser = AccountUtils.getLoginUser();
        Arguments.isTrue(!AccountInfoTypeEnum.HotelManager.value().equals(loginUser.getType())
                && !AccountInfoTypeEnum.Administrator.value().equals(loginUser.getType()), "您无权调用");
        financeWithdrawalParam.setType(HotelWithdrawalOrder.OrderType.VIP.value());
        if (!hotelWithdrawalOrderService.vipHotelWithdrawal(loginUser, financeWithdrawalParam)) {
            throw new ServiceException("新增提现订单异常");
        }
        return AjaxResponseBody.success(true);
    }

    @NeedToken
    @ApiOperation(value = "提现订单查询", notes = "提现订单查询", response = HotelWithdrawalOrderResult.class)
    @PostMapping("/list")
    public AjaxResponseBody<PageResult> list(@Validated WithdrawalOrderParam param) {
        PageResult<HotelWithdrawalOrderResult> pageResult = hotelWithdrawalOrderService.myVipHotelList(AccountUtils.getLoginUser(), param);
        return AjaxResponseBody.success(pageResult);
    }

}
